#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include "stack.h"
void qsortNonR(int q[], int l, int r)
{
	Stack s;
	StackInit(&s);
}
void _mergeSort(int q[], int l, int r, int* tmp)
{
	if (l >= r) return;
	int mid = l + r >> 1;
	_mergeSort(q, l, mid, tmp);
	_mergeSort(q, mid + 1, r, tmp);
	int i = l, j = mid + 1, k = 0;
	while (i <= mid && j <= r)
	{
		if (q[i] < q[j])
			tmp[k++] = q[i++];
		else tmp[k++] = q[j++];
	}

	while (i <= mid) tmp[k++] = q[i++];
	while (j <= r) tmp[k++] = q[j++];
	for (int i = l, j = 0; i <= r; i++, j++)
		q[i] = tmp[j];

}
void mergeSort(int q[], int n)
{
	int* tmp = (int*)malloc(sizeof(int) * n);
	int mid = n >> 1;
	_mergeSort(q, 0, n - 1, tmp);

	free(tmp);
}
int main()
{
	int a[] = { 4, 1, 45, 42, 0, 6, 22, 12 };
	int sz = sizeof a / sizeof(int);
	//qsortNonR(a, 0, sz - 1);
	mergeSort(a, sz);
	for (int i = 0; i < sz; i++)
		printf("%d ", a[i]);
	return 0;
}